const state = {
    visitedTab: [], // 面包屑展示标签
    cachedTab: [] // 缓存标签
}

const mutations = {
    ADD_VISITED_TAB(state, tab) {
        if(state.visitedTab.every(v => v !== tab)) {
            state.visitedTab.push(tab);
        }
    },
    ADD_CACHED_TAB(state, tab) {
        if(state.cachedTab.every(v => v!== tab)) {
            state.cachedTab.push(tab);
        }
    },
    DELETE_CACHED_TAB(state, tab) {
        const index = state.cachedTab.findIndex(t => t === tab);
        if(index >= 0) {
            state.cachedTab.splice(index, 1);
        }
    }
}

const actions = {
    addVisited({commit}, payload) {
        commit('ADD_VISITED', payload)
    },
    addTab({commit}, payload) {
        commit('ADD_TAB', payload)

    },
    addCachedTab({commit}, payload) {
        commit('ADD_CACHED_TAB', payload)
    },
    deleteCachedTab({commit}, payload) {
        commit('DELETE_CACHED_TAB', payload)
    }
}

export default {
namespaced: true,
state,
mutations,
actions
}
  